package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.ReservationInfo;
import com.qf.entity.ReservationInfoDTO;
import com.qf.entity.ReservationInfoVO;
import com.qf.service.ReservationInfoService;
import com.qf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: ReservationInfoController
 * @Author: WangHao
 * @Date: 2025/4/28 21:59
 * @Description:
 * @Version: 1.0
 */

@RestController
@RequestMapping("/reservationInfo")
public class ReservationInfoController {

    @Autowired
    private ReservationInfoService reservationInfoService;


    // 分页查询
    @PostMapping("/findAll")
    public R findAll(@RequestBody ReservationInfoDTO reservationInfoDTO) {
        PageHelper.startPage(reservationInfoDTO.getPageNum(), reservationInfoDTO.getPageSize());
        List<ReservationInfo> list = reservationInfoService.findAll(reservationInfoDTO);
        PageInfo<ReservationInfo> pageInfo = new PageInfo<>(list);
        return R.ok(pageInfo);
    }

    // 添加
    @PostMapping("/addReservationInfo")
    public R addReservationInfo(@RequestBody ReservationInfoDTO reservationInfoDTO) {
        boolean op = reservationInfoService.addReservationInfo(reservationInfoDTO);
        if (!op){
            return R.fail();
        }
        return R.ok();
    }

    // 修改
    @PostMapping("/updateReservationInfo")
    public R updateReservationInfo(@RequestBody ReservationInfoDTO reservationInfoDTO) {
        boolean op = reservationInfoService.updateReservationInfo(reservationInfoDTO);
        if (!op){
            return R.fail();
        }
        return R.ok();
    }

    // 查询租房类型
    @GetMapping("/findTypeName")
    public R findReservationInfoType() {
        List<ReservationInfoVO> list = reservationInfoService.findReservationInfoType();
        return R.ok(list);
    }

    // 根据id单个删除
    @GetMapping("/deleteReservationInfo")
    public R delReservationInfoById(Integer id) {
        boolean op = reservationInfoService.delReservationInfoById(id);
        if (!op) {
            return R.fail();
        }
        return R.ok();
    }

    // 批量删除
    @GetMapping("/deleteReservationInfoBatch")
    public R delReservationInfoByIds(Integer[] ids) {
        boolean op = reservationInfoService.delReservationInfoByIds(ids);
        if (!op) {
            return R.fail();
        }
        return R.ok();
    }
}
